package com.agency8x.orgfix;

import java.util.regex.Pattern;

import com.jfinal.plugin.activerecord.dialect.SqlServerDialect;

/**
 * 修复分页中带orderby会出错的问题
 * @author SoChishun
 * @see http://www.jfinal.com/feedback/857?p=1#reply_start
 * @version 1.0 2017-5-18
 */
public class EnhSqlServerDialect extends SqlServerDialect {

	
	protected static class Holder {
		// "order\\s+by\\s+[^,\\s]+(\\s+asc|\\s+desc)?(\\s*,\\s*[^,\\s]+(\\s+asc|\\s+desc)?)*";
		private static final Pattern ORDER_BY_PATTERN = Pattern.compile(
			"order\\s+by\\s+[^,\\s]+(\\s+asc|\\s+desc)?(\\s*,\\s*[^,\\s]+(\\s+asc|\\s+desc)?)*",
			Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
	}
	@Override
	public String replaceOrderBy(String sql) {
		return Holder.ORDER_BY_PATTERN.matcher(sql).replaceAll("");
	}

}
